package cn.tedu.user.management.dao.persist.repository.impl;

import cn.tedu.rtms.commons.pojo.vo.PageData;
import cn.tedu.rtms.commons.util.PageInfoToPageDataConverter;
import cn.tedu.user.management.dao.persist.mapper.JobMapper;
import cn.tedu.user.management.dao.persist.repository.IJobRepository;
import cn.tedu.user.management.pojo.entity.Job;
import cn.tedu.user.management.pojo.vo.JobListItemVO;
import cn.tedu.user.management.pojo.vo.JobRawVO;
import cn.tedu.user.management.pojo.vo.JobStandardVO;
import cn.tedu.user.management.pojo.vo.UserListItemVO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 处理职位数据的数据访问实现类
 *
 * @author java@tedu.cn
 * @version 0.0.1
 */
@Slf4j
@Repository
public class JobRepositoryImpl implements IJobRepository {

    @Autowired
    private JobMapper jobMapper;

    public JobRepositoryImpl() {
        log.debug("创建数据访问实现类对象：JobRepositoryImpl");
    }

    @Override
    public int insert(Job job) {
        log.debug("开始执行【添加职位】的数据访问，参数：{}", job);
        return jobMapper.insert(job);
    }

    /*
    @Override
    public int insertBatch(List<Job> jobList) {
        log.debug("开始执行【批量插入职位】的数据访问，参数：{}", jobList);
        return jobMapper.insertBatch(jobList);
    }*/

    @Override
    public int deleteById(Long id) {
        log.debug("开始执行【根据ID删除职位】的数据访问，参数：{}", id);
        return jobMapper.deleteById(id);
    }

    /*@Override
    public int deleteByIds(Collection<Long> idList) {
        log.debug("开始执行【批量删除职位】的数据访问，参数：{}", idList);
        return jobMapper.deleteBatchIds(idList);
    }*/

    /*@Override
    public int updateById(Job job) {
        log.debug("开始执行【更新职位】的数据访问，参数：{}", job);
        return jobMapper.updateById(job);
    }*/

    /*@Override
    public int count() {
        log.debug("开始执行【统计职位的数量】的数据访问，参数：无");
        return jobMapper.selectCount(null);
    }*/

    @Override
    public int countByJobName(String jobName) {
        log.debug("开始执行【根据职位名统计职位的数量】的数据访问，参数：{}", jobName);
        QueryWrapper<Job> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("job_name", jobName);
        return jobMapper.selectCount(queryWrapper);
    }

   /* @Override
    public int countByPhone(String phone) {
        log.debug("开始执行【根据手机号码统计职位的数量】的数据访问，参数：{}", phone);
        QueryWrapper<Job> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("phone", phone);
        return jobMapper.selectCount(queryWrapper);
    }*/

    /*@Override
    public int countByEmail(String email) {
        log.debug("开始执行【根据电子邮箱统计职位的数量】的数据访问，参数：{}", email);
        QueryWrapper<Job> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("email", email);
        return jobMapper.selectCount(queryWrapper);
    }*/

    @Override
    public JobStandardVO getStandardById(Long id) {
        log.debug("开始执行【根据ID查询职位详情】的数据访问，参数：{}", id);
        return jobMapper.getStandardById(id);
    }

    /*@Override
    public JobLoginInfoVO getLoginInfoByJobname(String jobname) {
        log.debug("开始执行【根据职位名查询职位登录信息】的数据访问，参数：{}", jobname);
        return jobMapper.getLoginInfoByJobname(jobname);
    }
*/
    @Override
    public PageData<JobListItemVO> list(Integer pageNum, Integer pageSize) {
        log.debug("开始执行【查询职位列表】的数据访问，页码：{}，每页记录数：{}", pageNum, pageSize);
        PageHelper.startPage(pageNum, pageSize);
        List<JobListItemVO> list = jobMapper.list();
        PageInfo<JobListItemVO> pageInfo = new PageInfo<>(list);
        PageData<JobListItemVO> pageData = PageInfoToPageDataConverter.convert(pageInfo);
        return pageData;
    }

   /* @Override
    public List<JobListItemVO> regList() {
        log.debug("开始执行【查询注册列表】的数据访问");
        return jobMapper.regList();
    }*/

    @Override
    public int update(Job job) {
        log.debug("开始执行【更新职位信息】的数据访问，参数：{}", job);
        return jobMapper.updateById(job);
    }

    @Override
    public int countByJobNameAndNotId(Long id, String jobName) {
        log.debug("开始执行【统计匹配ID但不匹配职位名的职位数量】的数据访问，ID：{}，名称：{}", id, jobName);
        QueryWrapper<Job> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("job_name", jobName).ne("id", id);
        return jobMapper.selectCount(queryWrapper);
    }

    @Override
    public Long selectJobIdByJobName(String jobName) {
        log.debug("开始执行【根据职位名称获取职位Id】的数据访问，名称：{}", jobName);
        return jobMapper.selectJobIdByJobName(jobName);
    }

    @Override
    public int countBySectionJobId(Long id) {
        log.debug("开始执行【查看同名职位数量】的数据访问，id：{}", id);
        return jobMapper.countBySectionJobId(id);
    }

    @Override
    public JobRawVO getInfoById(Long id) {
        log.debug("开始执行【根据section_job表中的id查询sectionName和jobName等相关数据】的数据访问，id：{}", id);
        return jobMapper.selectInfoById(id);
    }

    @Override
    public List<JobListItemVO> selectByKeywords(String keywords) {
        log.debug("开始执行【根据关键字查询职位列表】的数据访问");
        return jobMapper.selectByKeywords(keywords);
    }


}
